/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Queens;

/**
 *
 * @author User
 */
public class Queen {
    public int row;
    public int column;
    public Queen neighbour;
    public char[] draw = new char[8];
    Queen(int w,Queen q)
    {
        column=1;
        row=w;
        neighbour=q;
    }
    public boolean Find()
    {
        while((neighbour!=null) && neighbour.Atack(row,column))
            if(!Check()) return false;
        return true;
    }
    public boolean Check()
    {
        if(column<8)
        {
            column++;
            return Find();
        }
        if(neighbour!=null)
        {
            if(!neighbour.Check()) return false;
        }
        else return false;
        column=1;
        return Find();
    }
    public boolean Atack(int temprow,int tempcolumn)
    {
        int dRow=temprow-row;
        if(tempcolumn==column || column+dRow==tempcolumn|| column-dRow==tempcolumn || temprow==row)
            return true;
        if(neighbour!=null)
            return neighbour.Atack(temprow, tempcolumn);
        return false;
    }
    public void paint ()
     {
      if (neighbour != null) neighbour.paint();
      for(int i=0;i<8;i++) draw[i]='0';
      draw[column-1]='X';
      for(int i=0;i<8;i++) System.out.print(draw[i] + " ");
      System.out.println();
     }
}
